Skip to content

Qualified call via an inline namespace in Microsoft mode finding a global function [GH #588] - #589

Open
daveedvdv-nvidia wants to merge 1 commit into
mainfrom
fix/588
Open

daveedvdv-nvidia wants to merge 1 commit into
mainfrom
fix/588

Conversation

@daveedvdv-nvidia

@daveedvdv-nvidia daveedvdv-nvidia commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #588.

In Microsoft permissive mode (which implies --no_dep_name), the overload set of a nonmember function called in a template is looked up again when the template is instantiated, so that declarations appearing after the template are found (symbol_for_template_param_unknown_entity_con_after_substitution in il.c). For a namespace-qualified name, that lookup is done in the qualifying namespace. However, when the name was found through an inline namespace or a using-directive, the saved lookup result is a namespace projection symbol, and those were always given an unqualified lookup instead. That lookup could find a function of the same name in the global namespace:

double f(float, double);
namespace N { inline namespace I { template<class T> T f(T, T); } }
template<class T, class = void> struct A { static const int n = 1; };
template<class T> struct A<T, decltype(void(N::f(T(), 1.0)))> {
  static const int n = 2;
};
static_assert(A<float>::n == 1);  // Failed with --ms_c++17.

Deduction for N::f<T> fails, but ::f(float, double) was selected instead. MSVC (19.37, with or without /permissive-) and EDG's other modes accept this.

Projection symbols were excluded because one created by an unqualified lookup has as its parent the namespace in which that lookup was done, not a qualifying namespace. A projection symbol created by a qualified lookup, however, has the qualifying namespace as its parent (see enter_synthesized_projection_symbol), so it now gets the qualified lookup too.

Summary by CodeRabbit

  • Bug Fixes
    • Fixed function lookup during template instantiation in Microsoft compatibility mode. Qualified calls that resolve through inline namespaces or using-directives now use the qualifying namespace, preventing unrelated global functions from being selected.

@daveedvdv-nvidia
daveedvdv-nvidia requested a review from a team November 24, 2026 15:34
@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

Microsoft-mode dependent-name lookup now uses the saved namespace’s qualified lookup for namespace projection symbols found through qualified lookup. A new regression test covers calls through inline namespaces and using-directives, with fixtures for Microsoft and standard C++ modes.

Changes: Qualified dependent-name lookup

Layer / File(s) Summary
Qualified re-lookup and regression coverage
src/il.c, tests/tests/regressions/gh-588.sft.cpp, tests/tests/regressions/.gh-588.rto/*, src/pending_changes/gh-588-ms-qualified-call-inline-namespace.txt
Microsoft-mode lookup uses the saved namespace’s qualified lookup for qualifying namespace projection symbols. The regression test checks inline namespace and using-directive calls, including mixed argument types and a later overload. The fixtures cover Microsoft C++17, Microsoft C++20, and standard C++17 modes. The issue note describes the lookup case.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Low

Suggested labels: bug

Suggested reviewers: darkarc, nv-cmeerw

Merge Risk: Minimal · up to 8f070

This fixes Microsoft permissive-mode instantiation of namespace-qualified template calls, which no longer fall back to a same-named global function when deduction fails. The change is narrow and limited to that mode, and it ships with regression tests. No merge-blocking risk was found.

Pre-merge checks: Passed 4

Check name Status Explanation
Description Check Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check Passed The title names the main change: a qualified call through an inline namespace in Microsoft mode was finding a same-named global function, and the PR changes re-lookup for namespace projection symbols …
Linked Issues check Passed [#588] The requirement is that, in Microsoft permissive mode (--no_dep_name), a namespace-qualified call to a function template found through an inline namespace or using-directive must not fall back …
Out of Scope Changes check Passed The change set has three parts, and each supports #588. (1) The il.c hunk changes only the projection-symbol condition in the Microsoft-mode re-lookup path. It adds an explanatory comment and does not…
Full details: Title check

Explanation

The title names the main change: a qualified call through an inline namespace in Microsoft mode was finding a same-named global function, and the PR changes re-lookup for namespace projection symbols so it uses qualified lookup. The title is specific and matches the linked issue #588 and the objectives. It is somewhat long (92 characters) but remains clear.

Full details: Linked Issues check

Explanation

[#588] The requirement is that, in Microsoft permissive mode (--no_dep_name), a namespace-qualified call to a function template found through an inline namespace or using-directive must not fall back to a same-named global function when deduction fails. In src/il.c, the condition in symbol_for_template_param_unknown_entity_con_after_substitution now admits namespace projection symbols whose sym->qualified_lookup is set. Those symbols take the qualified lookup in the qualifying namespace, not the unqualified lookup that found ::fn. The added regression test tests/tests/regressions/gh-588.sft.cpp covers the issue's can_call case (static_assert(!can_call<float, double>::value)). It also covers the test(int) SFINAE case through lib2 and the LATE=1 case, where a later overload in lib is found during instantiation of h. The test runs under --ms_c++17 and --ms_c++20 with --microsoft_version=1937. Limits: I read only the il.c hunk and the test source. I did not inspect the qualified_lookup field definition or the rest of the qualified branch. The PASS rests on the diff and the test content, not on an executed run.

Full details: Out of Scope Changes check

Explanation

The change set has three parts, and each supports #588. (1) The il.c hunk changes only the projection-symbol condition in the Microsoft-mode re-lookup path. It adds an explanatory comment and does not change other modes or unrelated lookup paths. (2) The regression test gh-588.sft.cpp and its .rto fixtures test the reported behavior and its LATE variant. (3) The pending_changes note documents the fix. The PR description states that the change is limited to projection symbols from qualified lookup, which matches the diff. No unrelated change was found in the inspected hunk.

Finishing Touches

Generate unit tests (beta)

  • Commit to this branch
  • Create a new PR
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

Commits

Reviewing files that changed from the base of the PR and between 0d4f185 and 8f07018.

Files selected for processing: 6

  • src/il.c
  • src/pending_changes/gh-588-ms-qualified-call-inline-namespace.txt
  • tests/tests/regressions/.gh-588.rto/default.1.1.txt
  • tests/tests/regressions/.gh-588.rto/default.2.1.txt
  • tests/tests/regressions/.gh-588.rto/default.3.1.txt
  • tests/tests/regressions/gh-588.sft.cpp

Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.

@edgcpp-bot

Copy link
Copy Markdown
Collaborator

AcknowlEDG review results updated for 8f07018b9825:

@edgcpp-bot

Copy link
Copy Markdown
Collaborator

AcknowlEDG review results updated for 8f07018b9825:

CI success.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Microsoft mode: qualified call of a function template found through an inline namespace can select a global function

2 participants